<template>
  <section class="app-main">
    <router-view v-slot="{ Component }">
      <transition name="fade-transform" mode="out-in">
        <keep-alive :include="cachedViews">
          <component :is="Component" :key="key" />
        </keep-alive>
      </transition>
    </router-view>
  </section>
</template>

<script setup>
import { computed } from 'vue'
import { useRoute } from 'vue-router'
import { useAppStore } from '@/stores/app'

const route = useRoute()
const appStore = useAppStore()

const cachedViews = computed(() => appStore.cachedViews)
const key = computed(() => route.path)
</script>

<style lang="scss" scoped>
@use '@/styles/variables.scss' as *;

.app-main {
  min-height: calc(100vh - #{$header-height});
  width: 100%;
  position: relative;
  overflow: hidden;
  padding-top: $header-height;
  box-sizing: border-box;
}

.fixed-header + .app-main {
  padding-top: $header-height;
}

.hasTagsView {
  .app-main {
    min-height: calc(100vh - #{$header-height} - 34px);
  }

  .fixed-header + .app-main {
    padding-top: calc(#{$header-height} + 34px);
  }
}
</style>

<style lang="scss">
// fade-transform
.fade-transform-leave-active,
.fade-transform-enter-active {
  transition: all 0.5s;
}

.fade-transform-enter-from {
  opacity: 0;
  transform: translateX(-30px);
}

.fade-transform-leave-to {
  opacity: 0;
  transform: translateX(30px);
}
</style>
